import { useCounterStore } from "@/stores/counter";
import axios from "axios";
import { ElMessage } from "element-plus";
const store = useCounterStore()
//读
const postinfo = axios.create({
    baseURL: "http://localhost:5062/api",
    timeout: 5000
})

// 请求拦截器
postinfo.interceptors.request.use(
    confirm => {
        confirm.headers.Authorization = "Bearer" + store.userinfo.token
        return confirm
    },
    error => {
        return Promise.reject(error)
    }
)

//响应拦截器
postinfo.interceptors.request.use(
    res => {
        return res
    },
    error => {
        if (error.status == 401) {
            ElMessage.error('您尚未授权，请重新登录');
            setTimeout(() => {
                localStorage.href = "/"
            }, 1000);
        }
        return Promise.reject(error)
    }
)

//写
const xieInfo = axios.create({
    baseURL: "http://localhost:5007/api",
    timeout: 5000
})



export { postinfo, xieInfo }